package com.mobox.uav.view.weight;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

/**
 * Created by ${Clei} on 2018/5/23.
 */

public class OpenGLView extends GLSurfaceView {
    private OpenGLRendrere4 mRenderer;

    private float mDownX = 0.0f;
    private float mDownY = 0.0f;

    public OpenGLView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mRenderer = new OpenGLRendrere4();
        this.setRenderer(mRenderer);
    }

    public OpenGLView(Context context) {
        super(context);
        mRenderer = new OpenGLRendrere4();
        this.setRenderer(mRenderer);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int action = event.getActionMasked();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                mDownX = event.getX();
                mDownY = event.getY();
                return true;
            case MotionEvent.ACTION_UP:
                return true;
            case MotionEvent.ACTION_MOVE:
                float mX = event.getX();
                float mY = event.getY();
                float v = (mX - mDownX) / 10;
                float v1 = (mY - mDownY) / 10;
                Log.e("TAG", " V == " + v +"  V2==          " +v1   );
                mRenderer.mLightX += v;
                mRenderer.mLightY -= v1;
                mDownX = mX;
                mDownY = mY;
                return true;
            default:
                return super.onTouchEvent(event);
        }
    }

}
